﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace FlosVita.Model;

public class CustomerConfig : IEntityTypeConfiguration<Customer>
{
    public void Configure(EntityTypeBuilder<Customer> builder)
    {
        builder.ToTable("Customers");
        builder.HasKey(c => c.ID);
        builder.Property(c => c.ID).ValueGeneratedOnAdd();
        builder.Property(c => c.Name).IsRequired().HasMaxLength(15);
        builder.Property(c => c.Gender).IsRequired();
        builder.Property(c => c.BirthDate).IsRequired();
        builder.Property(c => c.PhoneNumber).IsRequired().HasMaxLength(15);
        builder.Property(c => c.CardID);
        builder.HasOne<Family>().WithMany().HasForeignKey(c => c.FamilyID);
    }
}

public class FamilyConfig : IEntityTypeConfiguration<Family>
{
    public void Configure(EntityTypeBuilder<Family> builder)
    {
        builder.ToTable("Families");
        builder.HasKey(f => f.ID);
        builder.Property(f => f.ID).ValueGeneratedOnAdd();
        builder.Property(f => f.Address).IsRequired();
    }
}

